package com.ruoyi.manager.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manager.domain.SoldierRetirement;
import com.ruoyi.manager.service.ISoldierRetirementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 军休安置Controller
 *
 * @author Allen
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/manager/retirement")
public class SoldierRetirementController extends BaseController {
    @Autowired
    private ISoldierRetirementService soldierRetirementService;

    /**
     * 查询军休安置列表
     */
    @PreAuthorize("@ss.hasPermi('manager:retirement:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoldierRetirement soldierRetirement) {
        startPage();
        List<SoldierRetirement> list = soldierRetirementService.selectSoldierRetirementList(soldierRetirement);
        return getDataTable(list);
    }

    /**
     * 导出军休安置列表
     */
    @PreAuthorize("@ss.hasPermi('manager:retirement:export')")
    @Log(title = "军休安置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SoldierRetirement soldierRetirement) {
        List<SoldierRetirement> list = soldierRetirementService.selectSoldierRetirementList(soldierRetirement);
        ExcelUtil<SoldierRetirement> util = new ExcelUtil<SoldierRetirement>(SoldierRetirement.class);
        return util.exportExcel(list, "军休安置数据");
    }

    /**
     * 获取军休安置详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:retirement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(soldierRetirementService.selectSoldierRetirementById(id));
    }

    /**
     * 新增军休安置
     */
    @PreAuthorize("@ss.hasPermi('manager:retirement:add')")
    @Log(title = "军休安置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoldierRetirement soldierRetirement) {
        return toAjax(soldierRetirementService.insertSoldierRetirement(soldierRetirement));
    }

    /**
     * 修改军休安置
     */
    @PreAuthorize("@ss.hasPermi('manager:retirement:edit')")
    @Log(title = "军休安置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoldierRetirement soldierRetirement) {
        return toAjax(soldierRetirementService.updateSoldierRetirement(soldierRetirement));
    }

    /**
     * 删除军休安置
     */
    @PreAuthorize("@ss.hasPermi('manager:retirement:remove')")
    @Log(title = "军休安置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(soldierRetirementService.deleteSoldierRetirementByIds(ids));
    }

    @PutMapping("/audit")
    @Log(title = "军休安置", businessType = BusinessType.UPDATE)
    public AjaxResult audit(@RequestParam("id") Long id, @RequestParam("auditStatus") Integer auditStatus) {
        return toAjax(soldierRetirementService.audit(id, auditStatus));
    }
}
